import http from '@/utils/http';
import type { MutationTree, ActionTree, GetterTree } from 'vuex'
import type { State } from '@/store'

interface Infos {
    [index:string]: unknown
}
export interface UsersState {
    token: string
    infos: Infos
}
const state: UsersState = {
    token: '',
    infos: {}
};
const mutations: MutationTree<UsersState> = {
    // 创建状态，更新状态
    updateToken(state, payload) {
        state.token = payload
    },
    updateInfos(state, payload) {
        state.infos = payload
    },
    clearToken(state) {
        state.token = ''
    }
};
const actions: ActionTree<UsersState, State> = {
    // 异步提交状态，动作
    login(context,playload){

        return http.post('/users/login',playload)
    },
    infos() {
      return http.get('/users/infos')
    },
};
// 对状态的值 进行计算
const getters: GetterTree<UsersState, State> = {};
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}
